
import { _decorator, Component, Node, UITransform, Color, Sprite } from 'cc';
import { Cell } from '../Constructs/Cell';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = CellNode
 * DateTime = Thu Sep 02 2021 18:24:47 GMT+0800 (中国标准时间)
 * Author = 幻想马修连恩
 * FileBasename = CellNode.ts
 * FileBasenameNoExtension = CellNode
 * URL = db://assets/Scripts/Prefabs/CellNode.ts
 * ManualUrl = https://docs.cocos.com/creator/3.3/manual/zh/
 *
 */
 
@ccclass('CellNode')
export class CellNode extends Component {
    @property
    sprite:Sprite = null;

    // [2]
    // @property
    // serializableDummy = 0;

    start () {
        // [3]
    }

    // update (deltaTime: number) {
    //     // [4]
    // }

    private _cell:Cell = null;
    initCellNode(cell:Cell,parentNode:Node,cellWidth,cellHeight){
        this._cell = cell;

        this.node.setParent(parentNode);
        let trans:UITransform = this.node.getComponent(UITransform);
        trans.width = cellWidth;
        trans.height = cellHeight;
        
        this.node.setPosition(cell.pos);
    }

    setCellColor(color:Color){
        this.sprite.color = color;
    }

    public getPos(){
        return this._cell.pos;
    }

    public active(active:boolean){
        this.node.active = active
    }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.3/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.3/manual/zh/scripting/ccclass.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.3/manual/zh/scripting/life-cycle-callbacks.html
 */
